#include "mealmodel.h"
#include <QDebug>

MealModel::MealModel(MealType type, QDate date,  QSqlDatabase *db, QObject *parent) :
    QSqlQueryModel(parent),
    m_type(type),
    m_db(db)
{

    setDate(date);
}

void MealModel::setDate(QDate date)
{
    QString queryString = QString(
                "SELECT m.rowid, f.foodName,m.foodAmount FROM foods f, meals m "
                "WHERE m.mealType = %1 AND m.mealDate = \"%2\" AND f.rowid = m.foodId")
            .arg(m_type)
            .arg(date.toString("yyyy-MM-dd"));
    this->setQuery(queryString, *m_db);
    //this->removeColumn(0);
    this->setHeaderData(0, Qt::Horizontal, "ID");
    this->setHeaderData(1, Qt::Horizontal, "Megnevezés");
    this->setHeaderData(2, Qt::Horizontal, "Mennyiség");
}
